/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trabalho_clinte;

import java.net.InetAddress;
import java.net.Socket;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.Thread;
import java.lang.Runnable;



public class RecebeAvisos_MULTIcast extends Thread {
    
    @Override
    public void run(){ 
        
           int port = 6001;
           String group="224.4.5.6";
        byte buffer[]= new byte[1000];
        Scanner sc = new Scanner(System.in);
        try {
           MulticastSocket Msocket = new MulticastSocket(port);// Criar socket
            Msocket.joinGroup(InetAddress.getByName(group));// Juntar-se ao grupo
            //DatagramSocket s = new DatagramSocket(port);
            DatagramPacket packet = new  DatagramPacket(buffer, buffer.length);
            
            Msocket.receive(packet);
            System.out.println("Servidor : " + packet.getData());
           
              // para sair
//       Msocket.leaveGroup(InetAddress.getByName(group));
//        Msocket.close();
        } catch (IOException ex) {
            Logger.getLogger(RecebeAvisos_MULTIcast.class.getName()).log(Level.SEVERE, null, ex);
        }
      
       
        
        
    
   }
}

